<!DOCTYPE html>
<html lang="ZH">
<head>
    <meta charset="UTF-8">
    <title>后台首页</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.css" rel="stylesheet">
    <script type="text/javascript" src="__PUBLIC__/js/jquery.timers.js"></script>
    <script type="text/javascript">
        var count = false;
        var time = 5;
        //处理订单
        $(document).ready(function () {
            $("input[name='deal']").click(function () {
                console.log('deal');
                var obj = $(this).parent().parent();
                var id = obj.children("td:first-child").text();
                console.log('id: '+id);
                $.ajax({
                    url: '/admin.php/Order/preDoneOrder/id/'+id,
                    method:'get',
                    dataType:'json',
                    success: function (res) {
                        if (res.code == 200) {
                            $("#order-page").empty();
                            $("#order-page").append(res.data);
                        }
                    }
                });
            });
        });
        //查看详情
        $(document).ready(function () {
            $("input[name='order_info']").click(function () {
                var obj = $(this).parent().parent();
                var id = obj.children("td:first-child").text();
                console.log('id: '+id);
                $.ajax({
                    url: '/admin.php/Order/getOrderInfo/id/'+id,
                    method:'get',
                    dataType:'json',
                    success: function (res) {
                        if (res.code == 200) {
                            $("#order-page").empty();
                            $("#order-page").append(res.data);
                        }
                    }
                });
            });
        });
        //查询预约订单
        $(document).ready(function () {
            $("#order-search").click(function () {
                console.log('search');
                var data = $("#order-form").serialize();
                console.log(typeof data,data);
                $.ajax({
                    url: "/admin.php/Order/searchOrder",
                    data: data,
                    method: 'post',
                    dataType: 'json',
                    success: function (res) {
                        if (res.code == 200) {
                            $("#order_table").empty();
                            $("#order_table").append(res.data);
                        } else if(res.code == 100) {
                            alert("未搜索到结果，请更改条件重试 !");
                        } else {
                            alert("查询失败，请稍后重试 !");
                        }
                    }
                });
            });
        });
        //删除
        $(document).ready(function () {
            $("input[name='order_delete']").click(function () {
                var obj = $(this).parent().parent();
                var id = obj.children("td:first-child").text();
                console.log('id: '+id);
                var r = confirm('确认删除吗？');
                if (r == true) {
                    $.ajax({
                        url: '/admin.php/order/deleteOrder/orderId/'+id,
                        dataType:'json',
                        success: function (res) {
                            if (res.code == 200) {
                                alert("删除成功");
                                obj.hide(500);
                            } else {
                                alert('删除失败');
                            }
                        }
                    });
                }
            });
        });
        //自动刷新未处理订单
        $(document).ready(function () {
            $("#refresh").click(function () {
                count = !count;
                if (count) {
                    $("#refresh").val('停止自动刷新');
                    $("#refresh").removeClass('btn-success');
                    $("#refresh").addClass('btn-danger');
                    $('body').everyTime('1s',refresh);
                } else {
                    $("#refresh").val('开始自动刷新');
                    $("#refresh").removeClass('btn-danger');
                    $("#refresh").addClass('btn-success');
                    $('body').stopTime();
                }
            });
        });
        //计时器
        function refresh() {
            $("#time_count").html('&nbsp;&nbsp;'+time);
            if (--time < 0) {
                time = 5;
                refresh_table();
            }
        }
        //表格刷新
        function refresh_table() {
            $.ajax({
                url: "/admin.php/Order/refresh",
                method: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.code == 200) {
                        $("#order_table").empty();
                        $("#order_table").append(res.data);
                    }
                }
            });
        }
    </script>
</head>
<body>
<div class="col-md-12" style="background-image: url('__PUBLIC__/img/logo.jpg');height: 120px;margin-bottom: 10px;">
    <div class="col-md-12 text-left">
        <h1><a href="{:U('index/index')}" style="text-decoration: none;color: white;">后台操作界面</a></h1>
    </div>
</div>
<div class="col-md-12 text-right" style="margin-bottom: 10px">
    <h7>当前登录用户&nbsp;&nbsp;<span><b>{$Think.session.user}</b></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{:U('index/logout')}">登出</a></h7>
</div>
<div class="col-md-12 row">
    <div class="col-md-2 text-center">
        <ul class="nav nav-pills nav-stacked">
          <li role="presentation" class="active">
				<a type="button" href="{:U('index/index')}" name="menu-btn" id="index" class="btn" style="width: 100%;">首&nbsp;&nbsp;页</a>
			</li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('order/index')}" name="menu-btn" id="order-menu" class="btn" style="width: 100%;">预约处理</a>
            </li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('good/index')}" name="menu-btn" id="good-menu" class="btn" style="width: 100%;">套餐管理</a>
            </li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('user/index')}" name="menu-btn" id="account-menu" class="btn" style="width: 100%;">用户管理</a>
            </li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('HomePage/index')}" name="menu-btn" id="banner-menu" class="btn" style="width: 100%;">首页设置</a>
            </li>
        </ul>
    </div>
    <div class="col-md-10">
        <div class="col-md-12 menu-page" id="order-page" style="border: 1px solid red;padding: 10px">
            <h3 style="margin-top: -5px">预约列表</h3>
            <div class="col-md-12 pull-left row">
                <form class="col-md-10 form-inline" id="order-form">
                    <label>预约状态</label>
                    <select name="status">
                        <option value="2" selected="selected">全部</option>
                        <option value="0">未处理</option>
                        <option value="1">已处理</option>
                    </select>
                    <label>预约日期</label>
                    <input type="date" name="start_date">
                    <label>至</label>
                    <input type="date" name="end_date">
                    <label>推荐人</label>
                    <input type="text" name="referrer">
                    <input type="button" id="order-search" value="搜索">
                    <input type="reset" value="重置">
                </form>
                <div class="col-md-2 pull-right row" style="height: 100%;margin-bottom: 5px">
                    <input type="button" id="refresh" class="btn btn-success" value="开启自动刷新">
                    <span id="time_count"></span>
                </div>
            </div>
            <div class="col-md-12" id="order_table">
                <div class="table-condensed" style="overflow-y: auto;overflow-x: auto;width: 100%;height: 700px">
                    <table class="table table-hover table-striped table-bordered text-center">
                        <tr>
                            <th class="text-center">序号</th>
                            <th class="text-center">姓名</th>
                            <th class="text-center">手机号</th>
                            <th class="text-center">省份证号码</th>
                            <th class="text-center">装机住址</th>
                            <th class="text-center">推荐人</th>
                            <th class="text-center">预约日期</th>
                            <th class="text-center">套餐类型</th>
                            <th class="text-center">套餐价格</th>
                            <th class="text-center">状态</th>
                            <th class="text-center">操作</th>
                        </tr>
                        <volist name="order_list" id="item">
                            <tr>
                                <td>{$item['id']}</td>
                                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['name']}</td>
                                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['phone']}</td>
                                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['id_card']}</td>
                                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['address']}</td>
                                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['referrer']}</td>
                                <td>{$item['order_date']|date="Y-m-d",###}</td>
                                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['good_name']}</td>
                                <td>{$item['good_price']}</td>
                                <td>{$item['status']?'已处理':'未处理'}</td>
                                <td>
                                    <if condition="$item['status'] eq 1">
                                        <input type="button" disabled="disabled" style="text-decoration: none;color: red" value="已处理">
                                        <else />
                                        <input type="button" name="deal" value="待处理">
                                    </if>
                                    <input type="button" name="order_info" value="详情">
                                    <input type="button" name="order_delete" style="color: darkred" value="删除">
                                </td>
                            </tr>
                        </volist>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>